
jBGallery.MenuSimple = function(el, data, engine, caption, options){
    
    var that = el;
    var _init = false;
  var _menu, _containers;
  var _h_play = _button('jbg-play', options.labels.play, play).toggle(!options.slideshow);
  var _h_stop = _button('jbg-stop', options.labels.stop, stop).toggle(options.slideshow);
  var _length = engine.length();
  //var _cnt = el; // options.fullscreen ? 'body' : el;//jbox
    
    //PRIVATE METHODS
    function _update_classes(ev){
        var _nr = engine.current();
    _menu.find("a.selected").removeClass("selected");
        _menu.find("a:eq("+ _nr +")").addClass("visited").addClass("selected");
    }
    function _button(css, label, callback){
        var _el = $('<a href="#" class="'+css+'">'+label+'</a>').click(function(){
            callback();
            return false;
        });
        return $("<li></li>").append(_el);
    }
    function _numbers(){
        var _html = '';
        for(var _x = 1; _x <= engine.length(); _x++)
            _html += '<li class="jbg-n"><a href="#">'+_x+'</a></li>';
        return _html;
    }
    function _delegation(ev){
        var _el = ev.target || ev.srcElement;
        if(_el.tagName.toString().toLowerCase() === 'a'){
            var _num = parseInt($(_el).text());
            engine.go(_num);
        }
        return false;
    }
  function play(){
    engine.play();
    _h_play.hide();
    _h_stop.show();
  }
  function stop(){
    engine.stop();
    _h_play.show();
        _h_stop.hide();
  }
  function _render(){
    if(!_init && engine.length() > 0){
      
      $('<div class="jbg-menu-opacity" /><ul class="jbg-menu" />').hide().appendTo(el);
        _menu = $('.jbg-menu', el);
            _containers = $('.jbg-menu-opacity , .jbg-menu', el);
                
        //NUMBERS
        if(options.menu == 'numbers'){
            _menu
                .append(_numbers())
            .click(_delegation)
            .find("a:eq(" + (engine.current() -1 )+ ")").addClass("selected").addClass("visited");
        }
        
        _menu
        .append(_button('jbg-next', options.labels.next, engine.right))
        .prepend(_button('jbg-prev', options.labels.prev, engine.left));
        //.appendTo(el);
        
      
        //SIMPLE
            //if(options.menu == 'simple'){
            _menu
            .append(_h_play)
            .append(_h_stop);
            //}
            
      if (options.caption) {
            _menu
            .append(_button('jbg-info', options.labels.info, function(){
                caption.toggle();
                return false;
            }));
        }
        
        if(options.popup){
            _menu
            .append(_button('jbg-close', options.labels.close, function(){
                $(that).trigger("destroy");
                options.close();
                return false;//15/12/2010
            }));
        }
        
        if(options.menu == 'numbers')
            engine.target.bind("load", _update_classes);
        
        if(options.autohide)
            jBGallery.AutoToggle($(_containers), options);
    
        $(_containers).fadeIn(options.timers.fade);
        
      _init = true;
    }
  }
    //
  function _empty(){
    if (options.menu == 'numbers') 
            $('.jbg-n', _menu).remove();
        $(_containers).fadeOut(options.timers.fade);
        _length = engine.length();
    }
  function _add_number(html){
    $('.jbg-next', _menu).parent().before(html);
  }
    function _add(o){
        if(!_init)
            _render();
          
        if ($.isArray(o)) {
      var _h = '';
      var _s = engine.length() - o.length;
            $.each(o, function(i, v){
                _h += '<li class="jbg-n"><a href="#">'+ (_s + i + 1) +'</a></li>';
            });
      _add_number(_h)
        }else{
            _add_number('<li class="jbg-n"><a href="#">'+ engine.length() +'</a></li>')
        }
        
    _update_classes();
    
        _length = engine.length();
    }
    function _remove(selector){
    $('li.jbg-n:last', _menu).remove();
    }
  _render();
  
  return {
    notify : function(m,o){
      if(data.length() > 0 && !$(_containers).eq(0).is(":visible")){
                $(_containers).fadeIn(options.timers.fade);
            }
      if (options.menu == 'numbers') {
        switch (m) {
          case 'push':
          case 'unshift':
            _add(o);
             break;
                    case 'pop':
          case 'shift':
            _remove();
            break;
            
        }
      }
      if (m == 'empty'){
        _empty();
      }
    }
  }
};

